<template>
	<view class="shop">
		<view class="top">
			<image v-if="info.banner == null" src="/static/new/banner_01.png" mode=""></image>
			<image v-else :src="info.banner | getImg" mode=""></image>
		</view>
		<view class="header">
			<view class="header_left">
				<image :src="info.img | getImg" mode=""></image>
				<text class="name">{{info.shop_name}}</text>
			</view>
			<view class="phonebox" @click="call">
				<uni-icons type="phone-filled" color="#ff0000"></uni-icons>
				<text>联系Ta</text>
			</view>
		</view>
		<view class="address" @click="toAddress">
			<text>{{info.shop_address}}</text>
			<uni-icons type="forward"></uni-icons>
		</view>
		<view class="info">
			<view class="infolist">
				<view class="left">
					营业时间
				</view>
				<view class="right">
					{{info.open_time}}
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left">
					商家介绍
				</view>
				<view class="right">
					{{info.content}}
				</view>
			</view>
			<view class="infolist">
				<view class="left">
					商家图片
				</view>
				<view class="right">
					<image @click="show_img" v-for="(item,index) in info.goods_img" :key="index" :src="item | getImg"
						mode=""></image>
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left">
					商家描述
				</view>
				<view class="right">
					{{info.main_project}}
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left" @click="toPage(shop_url)">
					商家链接
				</view>
				<view class="right">

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		ShopDetail,
		OfflineDetail
	} from "@/api/api.js"

	export default {
		data() {
			return {
				phone: '',
				info: [],
				goodsList: [],
				loadingText: "正在加载...",
				shop_url: '',
			}
		},
		onLoad(e) {
			if (e.id) {
				this.ShopDetail(e.id)
			} else if (e.offid) {
				this.OfflineDetail(e.offid)
			}

		},
		methods: {
			toPage(url) {
				if (url) {
					uni.navigateTo({
						url
					})
				}

			},
			call() {
				uni.makePhoneCall({
					phoneNumber: info.phone
				})
			},
			toAddress() {
				uni.openLocation({
					latitude: Number(this.info.latitude),
					longitude: Number(this.info.longitude),
					address: this.info.shop_address,
					name: this.info.address_name,
					success: (res) => {
						console.log(res);
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			show_img() {
				var arr = []
				for (var i = 0; i < this.info.goods_img.length; i++) {
					arr.push(getApp().globalData.data.websiteUrl + this.info.goods_img[i])
				}
				uni.previewImage({
					urls: arr
				})
			},
			ShopDetail(id) {
				ShopDetail({
					id: id
				}).then(res => {
					this.info = res.data
					this.info.goods_img = this.info.goods_img.split(',')
					this.shop_url = '../goodslist/goods-list?shop=' + this.info.id
					console.log(res);
				})
			},
			OfflineDetail(id) {
				OfflineDetail({
					id: id
				}).then(res => {
					this.info = res.data
					this.info.goods_img = this.info.goods_img.split(',')
					this.shop_url = '../goodslist/goods-list?offline=' + this.info.id
					console.log(res);
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.info.phone
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f3f3f3;
	}

	.top {
		image {
			width: 100%;
			height: 130px;
		}
	}

	.header {
		display: flex;
		padding: 0 15px;
		box-sizing: border-box;
		justify-content: space-between;

		.header_left {
			display: flex;
			width: 80%;
		}

		image {
			margin-top: -20px;
			width: 50px;
			height: 50px;
		}

		.name {
			font-size: 14px;
			font-weight: bold;
			margin-left: 5%;
			max-width: 70%;
		}

		.phonebox {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-top: 10px;


			text {
				font-size: 14px;
				color: #ff0000;
			}
		}

	}

	.address {
		padding: 0 5%;
		font-size: 14px;
		margin-top: 20px;
		color: #999;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.min_height_80 {
		min-height: 80px;
	}

	.info {
		.infolist {
			display: flex;
			padding: 0 5%;
			margin-top: 20px;
			font-size: 14px;

			.left {
				width: 25%;
			}

			.right {
				width: 75%;
				display: flex;
				flex-wrap: wrap;

				image {
					width: 32%;
					margin: 0 1%;
					height: 80px;
				}
			}
		}
	}
</style>
